#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void integralImagem (double **integral, double** imagem, int tam){
    int i, j, x, y;

    for (i = 0; i < tam; i++)
        for (j = 0; j < tam; j++)
            integral[i][j] = 0;

    double somatorio = 0;

    for (i = 0; i < tam; i++){
        for (j = 0; j < tam; j++){

            somatorio = 0;
            //printf("i = %d, j = %d\n", i, j);
            for (x = 0; x <= i; x++)
                for (y = 0; y <= j; y++)
                    somatorio += imagem[x][y];

            integral[i][j] = somatorio;
        }
    }
}

double somaPixels (double** integral, int coorX, int coorY, int ateX, int ateY){
    double retorno = 0;
    int i, j;

    for (i = coorX; i < ateX; i++){
        for (j = coorY; j < ateY; j++){
            retorno += integral[j][i];
        }
    }

    return retorno;
}
